package cn.dansj.common.utils.json;

import cn.dansj.common.utils.transfer.Transformation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

class BooleanDeserializer extends JsonDeserializer<Boolean> {
    public static final BooleanDeserializer INSTANCE = new BooleanDeserializer();

    @Override
    public Boolean deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        if (p.currentToken() == JsonToken.VALUE_STRING) return Transformation.castToBoolean(p.getText());
        return p.getValueAsBoolean();
    }
}
